package activitys;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.boboqi.test.R;

import java.util.ArrayList;
import java.util.List;

import adapters.FragmentTabLayoutPageAdapter;

/**
 * Created by pc on 2017/3/2.
 */

public class TabLayoutActivity extends AppCompatActivity {

    TabLayout tabLayout;
    ViewPager viewpager;

    List<String> list = new ArrayList<>();
    FragmentTabLayoutPageAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tablayout);
        tabLayout = (TabLayout) findViewById(R.id.tb);
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        for (int i = 0; i < 20; i++) {
            list.add("TAB" + i);
        }
        adapter = new FragmentTabLayoutPageAdapter(getSupportFragmentManager(), this);
        adapter.setData(list);
        viewpager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewpager);
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            tab.setCustomView(adapter.getTabView(i));
        }
    }
}
